define(['angular'], function (angular) {

/*-----------------------------------------
 *   demo serice
 ------------------------------------------*/
angular.module('books.service.bookMain', [])
    .constant('bookMainServiceConfig', {
        files:{//调用json数据
            retrNoteList:'app/data/demo/indexCount.json',
            retrIndexCount:'app/data/demo/indexCount.json'
        },
        urls:{
            retrNoteList:'http://47.92.95.246:8012/listnoteTop',//查询于都笔记
            retrIndexCount:'http://47.92.95.246:8012/indexCount'
        }
    })
    .factory('bookMainService',['$http', '$q', 'bookMainServiceConfig', function ($http, $q, bookMainServiceConfig) {
        return {
            /**
             * 查询tableList 列表
             */
            retrNoteList: function(){
                //内置服务 同步请求数据
                var deffered = $q.defer();
                //请求数据
                $http({
                    method:'GET',
                    dataType: "json",
                    contentType:'application/json; charset=UTF-8',
                    url:bookMainServiceConfig.urls.retrNoteList
                })
                .success(function(response){
                    deffered.resolve(response);
                })
                .error(function(e, code){
                    deffered.reject(code);
                });
                return deffered.promise; 
            },

            /**
             * 保存grid修改
             * 
             * @return {[type]} [description]
             */
            retrIndexCount: function(saveJson){
                //内置服务 同步请求数据
                var deffered = $q.defer();
                //请求数据
                $http({
                    method:'GET',
                    dataType: "json",
                    contentType:'application/json; charset=UTF-8',
                    // url:bookMainServiceConfig.urls.retrIndexCount
                    url:bookMainServiceConfig.urls.retrIndexCount
                })
                .success(function(response){
                    deffered.resolve(response);
                })
                .error(function(e, code){
                    deffered.reject(code);
                });
                return deffered.promise;    
            }
            
        };
    }]);

});
